package com.szmmsoft.mp.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.szmmsoft.mp.common.model.R;
import com.szmmsoft.mp.model.dto.AccountLoginDTO;
import com.szmmsoft.mp.model.entity.User;
import com.szmmsoft.mp.model.vo.LoginVO;
import com.szmmsoft.mp.service.UserService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * Description of the class.
 *
 * @author ethan
 * @version 1.0.0
 * @since 2024-10-16
 */

@RequestMapping("api/auth/v1")
@RestController
@Api(tags = "登录")
public class LoginController {
    @Autowired
    private UserService userService;

    @PostMapping("/account")
    @ApiOperation("账号密码登录")
    public R<LoginVO> accountLogin(@Validated @RequestBody AccountLoginDTO loginReq, HttpServletRequest request) {

        return userService.accountLogin(loginReq);
    }

    @GetMapping("login")
    @ApiOperation("小程序登录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "微信code", required = true),
            @ApiImplicitParam(name = "invitationCode", value = "邀请码"),
    })

    public R<LoginVO> login(String code) {
        return R.ok(userService.wxLogin(code));
    }

    @GetMapping("mock_login")
    @ApiOperation("小程序模拟登录")
    @ApiImplicitParam(name = "id", value = "1")
    public R<LoginVO> mockLogin(Long id, String invitationCode) {
        LoginVO loginVO =LoginVO.builder().build();
        return R.ok(loginVO);
    }
}
